package com.lb.design.pattern.singleton.register;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author lb
 * @Title: ContainerSingleton
 * @Description: TODO
 * @date 2019/03/12  17:51
 */
public class ContainerSingleton {
    private ContainerSingleton(){}
    private static Map<String,Object> iocContainer = new ConcurrentHashMap<String,Object>();
    public static Object getInstance(String className){

        synchronized (iocContainer){
            if (!iocContainer.containsKey(className)){
                Object o =null;
                try {
                    o = Class.forName(className).newInstance();
                    iocContainer.put(className,o );
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return o;
            }else {
                return iocContainer.get(className);
            }
        }
    }
}
